import { Effect, ImmerReducer, Reducer, Subscription } from 'umi';

export interface IndexModelState {
  title: string;
}

export interface IndexModelType {
  namespace: 'admin';
  state: IndexModelState;
  effects: {
    query: Effect;
  };
  reducers: {
    save: Reducer;
    changTitle: Reducer;
  };
  subscriptions: { setup: Subscription };
}

const IndexModel: IndexModelType = {
  namespace: 'admin',

  state: {
    title: 'abc',
  },

  effects: {
    *query({ payload }, { call, put }) {},
  },
  reducers: {
    save(state, action) {
      return {
        ...state,
        ...action.payload,
      };
    },
    changTitle(state, action) {
      return {
        ...state,
        title: action.payload,
      };
    },
  },
  subscriptions: {
    setup({ dispatch, history }) {
      return history.listen(({ pathname }) => {
        // if (pathname === '/') {
        //   dispatch({
        //     type: 'query',
        //   });
        // }
        // 监听pathname，pathname去跟menuList去比对
        // 将匹配到的title传到changTitle里面
      });
    },
  },
};

export default IndexModel;
